package ufsj.gamedevice;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class GameDevice extends Activity
{
    public static String user;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final EditText usuario = (EditText) findViewById(R.campo.usuario);
        final EditText senha = (EditText) findViewById(R.campo.senha);
        
        final TextView retorno = new TextView(this);
        Button botao = (Button) findViewById(R.botao.btUsuario);
        
        botao.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                try{
                    if(validarLogin(usuario.getText().toString(), senha.getText().toString())){
                        Intent outraTela = new Intent(GameDevice.this, Logado.class);
                        GameDevice.this.startActivity(outraTela);
                        user = usuario.getText().toString();
                        
                        GameDevice.this.finish();
                        
                    }else{
                        trace("Usuário ou senha inválidos!");
                    }
                }catch(Exception ex){
                    trace("Erro na conexão!");
                }
                
            }
        });
    }
    
    public boolean validarLogin(String usuario, String senha){
        if(usuario.equals("ufsj") && senha.equals("ufsj")){ 
            return true;
        }else{ 
            return false;
        }
    }
    
    private void trace (String msg) 
    {
        Toast.makeText (getApplicationContext(), msg, Toast.LENGTH_SHORT).show ();
    }
}
